package com.emergency.dfs.service.impl;

import com.emergency.dfs.service.DFSService;
import com.emergency.dfs.util.FastDFSClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;

/**
 * @Author lijie
 */
@Service
public class DFSServiceImpl implements DFSService {


	private static final Logger logger = LoggerFactory.getLogger(DFSService.class);


	@Override
	public String uploadFile(MultipartFile file) {
		String originalFilename = file.getOriginalFilename();
		String name = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
		String fullPath="";
		try {
			fullPath = FastDFSClient.uploadFile(file.getBytes(), name);
		} catch (IOException e) {
			logger.error("上传失败");
			e.printStackTrace();
		}
		return fullPath;
	}

	@Override
	public boolean downloadFile(String fileUrl, File file) {
		boolean flag= FastDFSClient.downloadFile(fileUrl,file);
		return flag;
	}

	@Override
	public boolean deleteFile(String fileUrl) {
		boolean flag=FastDFSClient.deleteFile(fileUrl);
		return flag;
	}
}
